package com.wzy.alllearning.config;

import java.time.LocalDateTime;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

/**
 * mybatis plus 自动填充配置
 */
@Component
public class CommonMetaObjectHandler implements MetaObjectHandler
{

	@Override
	public void insertFill(MetaObject metaObject)
	{
		this.strictInsertFill(metaObject, "created", LocalDateTime.class, LocalDateTime.now());
		this.strictInsertFill(metaObject, "modified", LocalDateTime.class, LocalDateTime.now());
		this.strictInsertFill(metaObject, "creator", String.class, "admin");
		this.strictInsertFill(metaObject, "operator", String.class, "admin");
		this.strictInsertFill(metaObject, "status", Integer.class, 0);
		this.strictInsertFill(metaObject, "version", Long.class, 1L);
	}

	@Override
	public void updateFill(MetaObject metaObject)
	{
		this.strictUpdateFill(metaObject, "modified", LocalDateTime.class, LocalDateTime.now());
		this.strictUpdateFill(metaObject, "operator", String.class, "admin");

	}
}
